/* 封装和文章相关的接口 */
import axios from '@/utils/request'

export function getArticles (id, timestamp) {
  return axios({
    method: 'get',
    url: '/v1_0/articles',
    params: {
      channel_id: id,
      timestamp,
      with_top: 1
    }
  })
}

// 对文章不喜欢
export function dislikeArticle (id) {
  return axios({
    method: 'POST',
    url: '/v1_0/article/dislikes',
    data: {
      target: id
    }
  })
}

export function reportArticle (id, type) {
  return axios({
    method: 'POST',
    url: '/v1_0/article/reports',
    data: {
      target: id,
      type
    }
  })
}

export function suggestArticle (q) {
  return axios({
    method: 'get',
    url: '/v1_0/suggestion',
    params: {
      q
    }
  })
}

export function searchArticle (page, q) {
  return axios({
    method: 'GET',
    url: '/v1_0/search',
    params: {
      page,
      per_page: 10,
      q
    }
  })
}

export function getArticleDetail (id) {
  return axios({
    method: 'get',
    url: '/v1_0/articles/' + id
  })
}

export function addFollow (id) {
  return axios({
    method: 'POST',
    url: '/v1_0/user/followings',
    data: {
      target: id
    }
  })
}

export function delFollow (id) {
  return axios({
    method: 'delete',
    url: '/v1_0/user/followings/' + id
  })
}

export function addGood (id) {
  return axios({
    method: 'post',
    url: '/v1_0/article/likings',
    data: {
      target: id
    }
  })
}

export function delGood (id) {
  return axios({
    method: 'delete',
    url: '/v1_0/article/likings/' + id
  })
}
